package Practice;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class cardList {

    private static final String[] SUIT = {"♥", "♣", "♦", "♠"};//全局变量

    public static List<Card> buyCards() {
        List<Card> list = new ArrayList<>();
        for (int i = 0; i < SUIT.length; i++) {
            for(int j = 1; j <= 13; j++) {
                Card card = new Card(SUIT[i], j);
                list.add(card);
            }
        }
        return list;
    }

    public static void shuffle(List<Card> list) {//洗牌
        Random random = new Random();
        for(int i = list.size() - 1; i > 0; i--) {
            int ret = random.nextInt(i);
            swap(list, i, ret);
        }
    }

    private static void swap(List<Card> list, int i, int j) {//交换
        Card tmp = list.get(i);
        list.set(i, list.get(j));
        list.set(j, tmp);
    }

    public static void main(String[] args) {
        List<Card> list = buyCards();
        System.out.println(list);
        shuffle(list);//洗牌
        System.out.println(list);
        //三个人每轮摸1张牌，摸5轮

        List<List<Card>> total = new ArrayList<>();

        List<Card> list1 = new ArrayList<>();
        List<Card> list2 = new ArrayList<>();
        List<Card> list3 = new ArrayList<>();

        total.add(list1);
        total.add(list2);
        total.add(list3);

        for (int i = 0; i < 5; i++) {//摸5轮
            for(int j = 0; j < 3; j++) {//3人
                Card card = list.remove(0);//每次摸得是第一张牌
                total.get(j).add(card);
            }
        }
        System.out.println("1:" + total.get(0));
        System.out.println("2:" + total.get(1));
        System.out.println("3:" + total.get(2));
        System.out.println("left:" + list);
    }
}
